<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <cpn></cpn>
        <cpn></cpn>
        <cpn></cpn>
    </div>

    <template id="cpn">
        <div>
            <h2>商品数量:{{num}}</h2>
            <button @click="sub">-</button>
            <button @click="add">+</button>
        </div>
    </template>
    <script src="vue.js"></script>
    <script>
        let data = {
            cmessage: "sdfsd",
            num: 0
        }
        const app = new Vue({
            el:"#app",
            data:{
                message:"app的data"
            },
            components:{
                cpn: {
                    template:`#cpn`,
                    data:function(){
                        return {
                            cmessage:"",
                            num: 0
                        }
                    },
                    methods:{
                        sub(){
                            this.num --;
                        },
                        add(){
                            this.num ++;
                        }
                    }
                }
            }
        });
    </script>
</body>
</html>